class Dir
  
  def self.exists?(dir)
    begin
      Dir.chdir(dir);
      Dir.chdir("../");
      return true;
    rescue
      return false
    end
  end
  
  def self.dir?(*args)
    self.exists?(*args)
  end
  
  def self.create(dir, move=true)
    unless self.exists?(dir)
      self.mkdir(dir)
    end
    self.chdir(dir) if move
  end
  
  def self.clean(dir, delete=false)
    old_dir = Dir.pwd
    Dir.chdir(dir)
    Dir.entries("./").delete_if{|e| [".", ".."].include? e;}.each do |entry|
      if entry.include?(".")
        File.delete(entry)
      elsif self.dir?(entry)
        self.clean(entry, true)
      end        
    end
    Dir.chdir(old_dir)
    Dir.rmdir(dir) if delete
  end
  
end

class File
  
  def self.create(name, content="")
    File.open(name, "w") do |file|
      file << content
    end
  end
  
end

def try(ok=true, error=false)
  begin
    yield;
    return ok;
  rescue
    return error;
  end
end

puts(lambda{

def create(n, ext="txt", content="Lorem Ipsum\n")
  Dir.create("teste") unless Dir.pwd.include?("teste")
  n.times do |i|
    try{File.create "#{i}.#{ext}", content * i}
  end
end

def delete(n, ext="txt")
  Dir.create("teste") unless Dir.pwd.include?("teste")
  n.times do |i|
    try{File.delete "#{i}.#{ext}"}
  end
end

#create(50, :exe)
Dir.clean("teste")
  

}.call());